package com.milhouz.bomberrokon.model;

/**
 * Represents a MapTile, this object contains the following properties :
 * <ul>
 * <li>Tile Indexes (X,Y) : Tile indexes in the map tile array</li>
 * <li>Tile coordonates (X,Y) : Tile coordonates in the screen (in px)</li>
 * <li>Object tile type : Object type of the tile</li>
 * <li>Sprite Index : Index of the tile in the map sprite array</li>
 * <li>Explosion bound : During an explosion, indicate if the tile is an explosion bound (updated each explosion)</li>
 * <li>Destructable : Indicate if the tile is destructable during an explosion (updated each explosion)</li>
 * </ul>
 * 
 * @author bpetetot
 */
public class Tile {

	private int indexTileX;
	private int indexTileY;
	private int tileX;
	private int tileY;
	private int tileSize;
	private int objectTile;
	private int spriteIndex;
	private boolean explosionBound;
	private boolean destructable;

	/**
	 * 
	 * @param indexTileX
	 *            The X index in the Tile[][] array of the mapModel
	 * @param indexTileY
	 *            The Y index in the Tile[][] array of the mapModel
	 * @param tileX
	 *            The X (upper of the tile) in pixel
	 * @param tileY
	 *            The Y (top of the tile) in pixel
	 * @param tileSize
	 *            The size of the tile
	 * @param objectType
	 *            Type code of the object
	 */
	public Tile(int indexTileX, int indexTileY, int tileX, int tileY, int tileSize, int objectType) {
		this.indexTileX = indexTileX;
		this.indexTileY = indexTileY;
		this.tileSize = tileSize;
		this.tileX = tileX;
		this.tileY = tileY;
		objectTile = objectType;
	}

	/**
	 * Get the X index in the Tile[][] array of the mapModel
	 * 
	 * @return The X index in the Tile[][] array of the mapModel
	 */
	public int getIndexTileX() {
		return indexTileX;
	}

	/**
	 * Get the Y index in the Tile[][] array of the mapModel
	 * 
	 * @return The Y index in the Tile[][] array of the mapModel
	 */
	public int getIndexTileY() {
		return indexTileY;
	}

	/**
	 * Get the X coordonate (left) of the tile in the screen (in px)
	 * 
	 * @return the X coordonate (left) of the tile in the screen (in px)
	 */
	public int getTileX() {
		return tileX;
	}

	/**
	 * Get the Y coordonate (top) of the tile in the screen (in px)
	 * 
	 * @return the Y coordonate (top) of the tile in the screen (in px)
	 */
	public int getTileY() {
		return tileY;
	}

	/**
	 * Get the CENTER X coordonate of the tile in the screen (in px)
	 * 
	 * @return the CENTER X coordonate of the tile in the screen (in px)
	 */
	public int getCenterTileX() {
		return tileX + (tileSize / 2);
	}

	/**
	 * Get the CENTER Y coordonate of the tile in the screen (in px)
	 * 
	 * @return the CENTER Y coordonate of the tile in the screen (in px)
	 */
	public int getCenterTileY() {
		return tileY + (tileSize / 2);
	}

	/**
	 * Get the type code of the object
	 * 
	 * @return Type code of the object
	 */
	public int getObjectTile() {
		return objectTile;
	}

	/**
	 * Set the type code of the object
	 * 
	 * @param objectTile
	 *            Type code of the object
	 */
	public void setObjectTile(int objectTile) {
		this.objectTile = objectTile;
	}

	/**
	 * Get the index of the sprite (corresponding to the tile) in the map sprite array
	 * 
	 * @return The index of the sprite
	 */
	public int getSpriteIndex() {
		return spriteIndex;
	}

	/**
	 * Set the index of the sprite (corresponding to the tile) in the map sprite array
	 * 
	 * @param spriteIndex
	 *            The index of the sprite
	 */
	public void setSpriteIndex(int spriteIndex) {
		this.spriteIndex = spriteIndex;
	}

	/**
	 * During an explosion, indicate if the tile is an explosion bound
	 * 
	 * @return if the tile is an explosion bound
	 */
	public boolean isExplosionBound() {
		return explosionBound;
	}

	/**
	 * During an explosion, indicate if the tile is an explosion bound
	 */
	public void setExplosionBound(boolean explosionBound) {
		this.explosionBound = explosionBound;
	}

	/**
	 * Indicate if the tile is destructable during an explosion
	 * 
	 * @return true if is destructable, else false
	 */
	public boolean isDestructable() {
		return destructable;
	}

	/**
	 * Set if the tile is destructable during an explosion
	 */
	public void setDestructable(boolean destructable) {
		this.destructable = destructable;
	}

	/** Get the tile size (its a square) */
	public int getTileSize() {
		return tileSize;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Tile.x=").append(getIndexTileX()).append(",y=").append(getIndexTileY()).append(",type=").append(objectTile);
		return sb.toString();
	}

}
